<template>
    <div class="kanban">
        <el-form :model="form" class="app-search" ref="searchForm">
            <el-select class="app-search-item" clearable filterable placeholder="商户" size="medium"
                       style="width:100px;" v-model="form.merchantId"
            >
                <el-option :label="item.name" :value="item.id" v-for="item in merchants"/>
            </el-select>
            <el-input class="app-search-item" clearable placeholder="请输入关键字查询" size="medium"
                      style="width:220px;"
                      v-model="form.keyword"
            />
            <el-button @click="fetchData(1)" class="app-search-item" icon="el-icon-search" size="medium"
                       type="primary"
            >
                搜索
            </el-button>
        </el-form>
        <el-table :data="items" style="width: 100%">
            <el-table-column label="商户名称" prop="merchantName" width="100">
                <template slot-scope="scope">
                    <div class="template-name">
                        <b>{{scope.row.merchantName}}</b>
                    </div>
                </template>
            </el-table-column>
            <el-table-column label="类型" prop="type" width="150">
                <template slot-scope="scope">
                    <div class="template-name">
                        <b>{{scope.row.type | billTypeText}}</b>
                    </div>
                </template>
            </el-table-column>
            <el-table-column label="时间" prop="created" width="170">
                <template slot-scope="scope">
                    <div class="template-name">
                        <b>{{scope.row.created}}</b>
                    </div>
                </template>
            </el-table-column>
            <el-table-column label="金额" prop="amount" width="80">
                <template slot-scope="scope">
                    <div class="template-name">
                        <b>{{scope.row.amount | yuan}}</b>
                    </div>
                </template>
            </el-table-column>
            <el-table-column label="变更后" prop="balance" width="80">
                <template slot-scope="scope">
                    <div class="template-name">
                        <b>{{scope.row.balance | yuan}}</b>
                    </div>
                </template>
            </el-table-column>
            <el-table-column label="业务编号" prop="bizNo">
                <template slot-scope="scope">
                    <div class="template-name">
                        <b>{{scope.row.bizNo}}</b>
                    </div>
                </template>
            </el-table-column>
            <el-table-column label="描述" prop="description">
                <template slot-scope="scope">
                    <div class="template-name">
                        <b>{{scope.row.description}}</b>
                    </div>
                </template>
            </el-table-column>
        </el-table>
        <div class="block">
            <el-pagination :page-size="form.size" :total="form.total" @current-change="fetchData"
                           layout="prev, pager, next"
                           width="1000">
            </el-pagination>
        </div>
    </div>
</template>

<script>
    export default {
        name: 'Merchant',
        info: {},
        data() {
            return {
                form: {
                    page: 1,
                    size: 10,
                    total: 0,
                    merchantId: '',
                    keyword: ''
                },
                merchants: [],
                items: []
            }
        },
        methods: {
            fetchMerchants() {
                this.$fetch('/admin/merchant/list?page=1&size=9999').then(res => {
                    if (res.code === 0) {
                        this.merchants = res.data.records
                    } else {
                        this.$message.error(res.errorMsg)
                    }
                })
            },
            fetchData(page) {
                if (page) {
                    this.form.page = page
                }
                this.$fetch('/admin/bill/list?merchantId=' + this.form.merchantId + '&keyword=' + this.form.keyword + '&page=' + this.form.page)
                    .then(res => {
                        if (res.code === 0) {
                            this.items = res.data.records
                        } else {
                            this.$message.error(res.errorMsg)
                        }
                    })
            },
        },
        mounted() {
            this.fetchMerchants();
            this.fetchData()
        }
    }
</script>
<style>
    .block {
        display: -webkit-flex;
        display: flex;
        justify-content: flex-end;
        padding: 15px 30px;
    }

    .kanban {
        padding: 25px 25px;
    }

    .el-image-viewer__img {
        width: 120px;
        height: 120px;
    }

</style>
